/*
 * @Author: your name
 * @Date: 2021-05-23 21:08:47
 * @LastEditTime: 2021-06-06 12:29:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/routers/index.tsx
 */
// import vip from '@/assets/img/vip.png';
// const home = require('@/assets/img/home.png');
// import home from '@/assets/img/home.png';
// import room from '@/assets/img/room.png';
// import staff from '@/assets/img/staff.png';
// import summary from '@/assets/img/summary.png';

import { IMenu } from '@/layouts/interface';
import { globalModel } from '@/pages/globalModel';
import _ from 'lodash';
import { observer } from 'mobx-react';
import { EPermission } from '../enum/index';
export const Menus: IMenu[] = [
  {
    key: 'home',
    name: '首页',
    icon: 'home.png',
    path: '/home',
    component: '@/pages/home/index',
  },
  {
    key: 'schedule',
    name: '排班管理',
    icon: 'schedule.png',
    path: '/schedule',
    component: '@/pages/schedule/index',
  },
  {
    key: 'scheduleApply',
    name: '加钟申请',
    icon: 'addSchedule.png',
    path: '/scheduleApply',
    component: '@/pages/scheduleApply/index',
  },
  {
    key: 'vip',
    name: '会员管理',
    icon: 'vip.png',
    path: '/vip',
    component: '@/pages/vip',
  },
  {
    key: 'goods',
    name: '商品管理',
    icon: 'vip.png',
    path: '/goods',
    component: '@/pages/goods',
  },

  {
    key: 'summary',
    name: '今日汇总',
    path: '/summary',
    icon: 'summary.png',
    component: '@/pages/summary',
  },
  {
    key: 'order',
    name: '订单管理',
    path: '/order',
    icon: 'order.png',
    component: '@/pages/order',
  },
  {
    key: 'project',
    name: '项目管理',
    path: '/project',
    icon: 'project.png',
    component: '@/pages/project',
  },
  {
    key: 'chain',
    name: '连锁店',
    path: '/chain',
    icon: 'summary.png',
    component: '@/pages/chain',
  },
  {
    key: 'store',
    name: '门店管理',
    path: '/store',
    icon: 'room.png',
    component: '@/pages/store',
  },
  {
    key: 'room',
    name: '包厢管理',
    path: '/room',
    icon: 'room.png',
    component: '@/pages/room',
  },
  {
    key: 'staff',
    name: '技师管理',
    path: '/staff',
    icon: 'staff.png',
    component: '@/pages/staff',
  },
  {
    key: 'account',
    name: '账号管理',
    path: '/account',
    icon: 'staff.png',
    component: '@/pages/account',
  },
  {
    key: 'vipCard',
    name: '会员卡',
    path: '/vipCard',
    icon: 'vip.png',
    component: '@/pages/vipCard',
  },
  {
    key: 'roomPage',
    name: '房间界面',
    path: '/roomPage',
    icon: 'room.png',
    component: '@/pages/roomPage',
  },
];

const permissionRouter = {
  [EPermission.SuperAdmin]: [
    // 'home',
    // 'vip',
    // 'goods',
    // 'summary',
    // 'order',
    // 'project',
    'chain',
    // 'store',
    // 'staff',
    'account',
  ],
  [EPermission.ChainAdmin]: [
    // 'home',
    // 'vip',
    // 'goods',
    'summary',
    'order',
    // 'project',
    'store',
    // 'staff',
    'vipCard',
    'account',
  ],
  [EPermission.StoreAdmin]: [
    'home',
    'schedule',
    'scheduleApply',
    'vip',
    // 'goods',
    'summary',
    'order',
    'room',
    'project',
    'staff',
  ],
};

export const MenuList = (box_id?: number, is_super?: number) => {
  let keys: string[] = [];
  if (box_id) {
    keys = ['roomPage'];
  } else if (is_super) {
    keys = permissionRouter[is_super as keyof typeof permissionRouter];
  }

  return _.filter(Menus, (row) => keys.includes(row.key));
};

export const Router = () =>
  _.reduce(Menus, (total, current) => total.concat(current), [
    {
      path: '/',
      redirect: Menus[0].path,
    },
    {
      path: '/login',
      component: '@/pages/login',
    },
  ]);
